package com.example.spring_forum.controller;

import com.example.spring_forum.common.AppResult;
import com.example.spring_forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "测试接口")
@Slf4j //日志
@RestController //在body中返回数据
@RequestMapping("/test") //一级路由映射
public class TestController {

    @ApiOperation("hello测试")
    @RequestMapping("/hello")
    public String hello(){

        return "hello,spring-boot";
    }

    @ApiOperation("hello测试")
    @RequestMapping("/helloByName(带参数)")
    public AppResult helloByName(@ApiParam("姓名") String name){
        return AppResult.success("你好："+name);
    }

    @ApiOperation("异常测试")
    @GetMapping("/exception")
    public AppResult testException() throws Exception{
        throw new Exception("这是一个Exception");
    }
    @ApiOperation("自定义异常测试")
    @GetMapping("/applicationException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException");
    }
}
